<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>项目管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript">
        var grid = null;
        $(function () {
            var _projectIdtmp = parent.pageInApp.projectid;
            var parms = {};
            if(typeof(_projectIdtmp) != "undefined" && _projectIdtmp != ""){
                parms.projectId = _projectIdtmp;
                parent.pageInApp.projectid="";
            }
            $("#ligergrid1").ligerGrid({
                url: '<%=path%>/infside/infWarrantPay/initInfWarrantPayList.do',
                parms: parms,
                method : 'get',
                columns: [
                    { display: '合同编号', name: 'leaseCode', minWidth: 180, align: 'center', enabledSort:true},
                    { display: '支付表编号', name: 'paylistCode', minWidth: 180, align: 'center', enabledSort:true},
                    { display: '融资额(元)', name: 'topricSubfirentdou', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '支付方式', name: 'payWay', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '交付方式', name: 'corporePayWay', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '是否上牌', name: 'isLicensedNm', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '起租日', name: 'startDate', minWidth: 100, render:renderDate, align: 'center', enabledSort:true},
                    { display: '实际放款时间', name: 'payDate', minWidth: 100, render:renderDate, align: 'center', enabledSort:true},
                    { display: '结清日期', name: 'endDate', minWidth: 100, render:renderDate, align: 'center', enabledSort:true},
                    { display: '放款状态', name: 'paymentStatus', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '发送状态', name: 'statusNm', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '返回信息', name: 'message', minWidth: 300, align: 'center', enabledSort:true},
                    {
                        display: '操作',minWidth: 100,align: 'center',
                        render: function (rowdata, rowindex, value){
                            var h1='<span style="color:#C9C9C9;">明细</span>';
                            if(rowdata.paymentStatus != ""){
                                h1='<a href="javascript:void(0);" onclick="searchPaylistDetail(\''+rowdata.paylistCode+'\')">明细</a>';
                            }
                            var h2='<span style="color:#C9C9C9;">发送</span>';

                            if(rowdata.status=='sendWait'){
                                //未发送
                                h2='<a href="javascript:void(0);" onclick="paymentBefore(\''+rowdata.projectId+'\',\''+rowdata.paylistCode+'\')">发送</a>';
                            }else if(rowdata.status=='loanWait' || rowdata.status=='loanFailure'){
                                //放款失败 未放款
                                h2='<a href="javascript:void(0);" onclick="paymentAfter(\''+rowdata.projectId+'\',\''+rowdata.paylistCode+'\')">发送</a>';
                            }else if(rowdata.status=='settleUnsynced'){
                                //结清发送失败
                                h2='<a href="javascript:void(0);" onclick="changePayStatus(\''+rowdata.projectId+'\',\''+rowdata.paylistCode+'\')">发送</a>';
                            }

                            return h1+'&nbsp;&nbsp;&nbsp;&nbsp;'+h2;
                        }
                    }
                ],
                pageSize:10,
                root:'rows',
                record:'total',
                hideLoadButton : true,
                width: '100%',
                height:'100%',
                heightDiff:-2,
                //checkbox:true,
                rownumbers:true
            });
            grid = liger.get("ligergrid1");
            grid.setHeight(100);
            $("#searchBar").ligerForm();
            $("#dateform").ligerForm();
            $("#searchBtn").click(function(event) {
                var form = new liger.get("searchBar");
                var data = form.getData();
                console.log(data);
                for (name in data){
                    grid.setParm(name,data[name]);
                };
                grid.setParm("projectId","");
                grid.reload();
            });
            $("#clearBtn").click(function(event) {
                clearLigerForm("searchBar");
            });
        });

        //明细
        function searchPaylistDetail(_paylistcode){
            if (parent.pageInTab) {
                parent.pageInApp.paylistcode=_paylistcode;
                parent.pageInTab.selectTabItem('WarrantProduct');
                parent.pageInTab.reload('WarrantProduct');
            }
        }

        //发送支付表-未发送
        function paymentBefore(_projectId,_paylistcode){
            $.ligerDialog.confirm("是否确认发送?", function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:'projectId='+_projectId+'&paylistCode='+_paylistcode,
                    url: '<%=path%>/infside/infWarrantPay/paymentBefore.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }

        //向权证系统发送支付表状态-结清
        function changePayStatus(_projectId,_paylistcode){
            $.ligerDialog.confirm("是否确认发送?", function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:'projectId='+_projectId+'&paylistCode='+_paylistcode,
                    url: '<%=path%>/infside/infWarrantPay/changePayStatus.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        //向权证系统发送放款完成信息（放款完成）
        function paymentAfter(_projectId,_paylistcode){
            $.ligerDialog.confirm("是否确认发送?", function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:'projectId='+_projectId+'&paylistCode='+_paylistcode,
                    url: '<%=path%>/infside/infWarrantPay/paymentAfter.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        //格式化时间
        function renderDate(rowdata, index, value){
            var dateStr = "";
            if(null != value){
                var date = new Date(value);
                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
            }
            return dateStr;
        }
    </script>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="leaseCode" id="leaseCode" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <input name="paylistCode" id="paylistCode" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">起租日(起)</div>
                    <div class="field">
                        <input name="beginDate" id="beginDate" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">起租日(止)</div>
                    <div class="field">
                        <input name="endDate" id="endDate" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">状态</div>
                    <div class="field">
                        <select name="status"  id="status"  disabled="disabled">
                            <option value="  " selected="selected">--请选择--</option>
                            <c:forEach items="${statuslist}" var="opt">
                                <option value="${opt.key}">${opt.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</body>
</html>
